﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Publish_NewsDetail : System.Web.UI.Page
{
    protected string m_title = "";
    protected string m_detail = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = "";
        if (Request.Params["id"] != null)
            id = Request.Params["id"].ToString();
        GssDO.DONews DO = getById(id);
        if (DO != null && DO.IsDeleted == 0 && DO.IsApprove == 1)
        {
            m_title = DO.Title;
            m_detail = ShowDetail(DO);
            DataTable dt = GetLatestOtherNews(10, DO.PKIDNews);
            if (dt != null && dt.Rows.Count > 0)
            {
                rptNews.DataSource = dt;
                rptNews.DataBind();
            }
        }
        else
            Response.Redirect(@"News.aspx", false);
    }

    private string ShowDetail(GssDO.DONews DO)
    {
        string rs = "";

        rs = "<p>";
        if (DO.Image != "")
        {
            rs += "<table align='left'><tr><td style='padding: 0px 10px 2px 0px;'>";
            rs += "<img alt='" + DO.Title.Trim() + "' src='../Photos/Event/" + DO.Image + "' border='0' align='left' onerror=\"this.src='../images/noimage90.gif'\" />";
            rs += "</td></tr></table>";
        }
        if (DO.Title.Trim() != "")
            rs += "<h3>" + DO.Title.Trim() + "<span>(" + DO.CreatedDate.ToString("yyyy/MM/dd")+ ")<span></h3>";
        if (DO.ShortText.Trim() != "")
            rs += "<p><strong>" + DO.ShortText.Trim() + "</strong></p>";
        rs += "<p><br></p>";
        rs += "<p>" + DO.Description.Trim() + "</p>";
        if (DO.Source != "")
            rs += "<p align='right'>Nguồn: " + DO.Source.Trim() + "</p>";

        return rs;
    }

    protected string BindNews(string id, string title, object datetime)
    {
        string rs = "";
        rs += "<a href='NewsDetail.aspx?id=" + id + "'>" + title + "</a> <span>(" + ((DateTime)datetime).ToString("yyyy/MM/dd") + ")</span>";
        return rs;
    }

    private DataTable GetLatestOtherNews(int row, string id)
    {
        DataTable dt = null;
        try
        {
            GssBL.BLNews BL = new GssBL.BLNews();
            dt = BL.getLatestOtherNews(row, id);
        }
        catch (Exception exc)
        {
            string mess = exc.Message.ToString();
            dt = null;
        }
        return dt;
    }

    private GssDO.DONews getById(string id)
    {
        GssDO.DONews DO = null;
        try
        {
            GssBL.BLNews BL = new GssBL.BLNews();
            DO = BL.getNewsByID(id);
        }
        catch (Exception ex)
        {
            string mess = ex.Message.ToString();
            DO = null;
        }
        return DO;
    }
}
